home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Day Cry
/
Day Cry CD.bin
/
oh_towns
/
taropyon
/
splib
/
splib.lzh
/
PRG
/
LHX
/
GETOPT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-08
|
2KB
|
78 lines
/***********************************************************
getopt.c -- get options
***********************************************************/
#include "lh386.h"
#include <ctype.h>
#ifndef __HIGHC__
# include <stddef.h>
#else
# include <stdefs.h>
#endif
#include <string.h>
#include "lh.h"
#ifdef __HIGHC__
# pragma On(Align_labels);
#endif
char flg_r, flg_p, flg_x, flg_m, flg_a, flg_c, flg_n, flg_t, flg_u,
flg_v, flg_w, flg_i, flg_h = 1, flg_o, flg_z;
/*******************************
get options
*******************************/
int getopt(char *p)
{
static char flg[] = "rpxmacntuvwihoz";
static char *flgpos[] =
{&flg_r, &flg_p, &flg_x, &flg_m, &flg_a,
&flg_c, &flg_n, &flg_t, &flg_u, &flg_v,
&flg_w, &flg_i, &flg_h, &flg_o, &flg_z};
static char val[] = "0-1+2";
int i;
char s;
char *q;
while ((s = tolower(*p)) != 0)
{
p++;
q = strchr(flg, s); /* search switch */
if (q)
{
i = q - flg;
if (*p && (q = strchr(val, *p)) != NULL)
{
*flgpos[i] = (q - val) / 2;
p++;
} else if (s == 'v' && *p)
{
if (flg_v == 0) /* process of '/vSTRING' */
flg_v = 1;
pager = p;
p = "";
} else if (s == 'w' && *p)
{
flg_w = 1; /* process of '/wSTRING' */
workdir = p;
p = "";
} else
{
/* flip-flop */
*flgpos[i] = !*flgpos[i];
}
} else if (s == 'k')
{
keyword = p;
p = "";
} else
{
if (s == '?')
usage();
return 1;
}
}
return 0;
}